package   com.NeuglsWorkStudio.UI.Buttons
{
	import flash.display.DisplayObject;
	
	public class TIconButton extends TEffectedButton
	{
		private var _FIconSize:Number = new Number(25);
		private var _FIconTextMargin:Number =new Number(2);
		private var _FCheckedIcon:DisplayObject =null;
		private var _FNoCheckedIcon:DisplayObject =null;
		private var _FChecked:Boolean =false;
		
		private var _FOldIcon:DisplayObject =null;
		
		public function TIconButton(ACaption:String="",IsHtml:Boolean=true,BaceColor:int=0x222222)
		{
			super(ACaption,IsHtml,BaceColor);
			//FCaptionField.x=_FIconSize+_FIconTextMargin;//初始化时没有图片，所以不加
		}

		public function get Checked():Boolean
		{
			return _FChecked;
		}

		public function set Checked(value:Boolean):void
		{
			_FChecked = value;
			Paint();
		}

		public function get NoCheckedIcon():DisplayObject
		{
			return _FNoCheckedIcon;
		}

		public function set NoCheckedIcon(value:DisplayObject):void
		{
			_FNoCheckedIcon = value;
			if(!_FChecked){
				Paint();
			}
		}

		public function get CheckedIcon():DisplayObject
		{
			return _FCheckedIcon;
		}

		public function set CheckedIcon(value:DisplayObject):void
		{
			_FCheckedIcon = value;
			if(_FChecked){
				Paint();
			}
		}

		public function get IconTextMargin():Number
		{
			return _FIconTextMargin;
		}

		public function set IconTextMargin(value:Number):void
		{
			_FIconTextMargin = value;
			FCaptionField.x=_FIconSize+_FIconTextMargin;
		}

		public function get IconSize():Number
		{
			return _FIconSize;
		}

		public function set IconSize(value:Number):void
		{
			_FIconSize = value;
			FCaptionField.x=_FIconSize+_FIconTextMargin;
		}
		
		protected function Paint():void{
			if(_FOldIcon!=null){
				this.removeChild(_FOldIcon);
			}
			
			if(_FChecked){
				_FOldIcon=_FCheckedIcon;
			}else{
				_FOldIcon=_FNoCheckedIcon;				
			}
			this.addChild(_FOldIcon);
			_FOldIcon.x=0;
			_FOldIcon.y=(this.Height-_FIconSize)/2;
		}
	}
}